package com.oauth.twitter.server.utils;

import java.util.ArrayList;
import java.util.List;

import twitter4j.Status;
import twitter4j.User;

import com.oauth.twitter.client.beans.Tweet;
import com.oauth.twitter.client.beans.TwitterUser;

public class TwitterConversionUtil {

	public static List<Tweet> convertToTweets(List<Status> pUserTimeline) {
		List<Tweet> tweetsList = new ArrayList<Tweet>();
		if (pUserTimeline != null) {
			for (Status status : pUserTimeline) {
				tweetsList.add(convertToTweet(status));
			}
		}
		return tweetsList;
	}

	public static Tweet convertToTweet(Status pStatus) {
		Tweet tweet = new Tweet();
		if (pStatus != null) {
			tweet.setText(pStatus.getText());
			tweet.setCreatedDate(pStatus.getCreatedAt().toString());
			tweet.setUser(convertToUser(pStatus.getUser()));
		}
		return tweet;
	}

	public static TwitterUser convertToUser(User pUser) {
		TwitterUser user = new TwitterUser();
		if (pUser != null) {
			user.setId(Long.toString(pUser.getId()));
			user.setName(pUser.getName());
			user.setProfileImageUrl(pUser.getProfileImageURL() != null ? pUser.getProfileImageURL()
					.toString() : "");
			user.setProfileLinkColor(pUser.getProfileLinkColor());
			user.setStatus(pUser.getStatus() != null ? pUser.getStatus().getText() : "");
		}
		return user;
	}
}
